﻿

#region Using Statements

using UnityEngine;
using System.Collections.Generic;

#endregion


/// <summary>
/// 
/// </summary>
public class WSADFly : MonoBehaviour
{

    #region Members

    /// <summary>
    /// Speeds for each independent axis of motion (x,y,z).
    /// </summary>
    public Vector3 axialSpeeds = Vector3.one * 10.0f;


    /// <summary>
    /// Name for input zAxis motion.
    /// </summary>
    public string zAxis = "Vertical";


    /// <summary>
    /// Name for input xAxis motion.
    /// </summary>
    public string xAxis = "Horizontal";


    /// <summary>
    /// Name for input yAxis motion.
    /// </summary>
    public string yAxis = null;


    /// <summary>
    /// Whether or not to use fixed update.
    /// </summary>
    public bool useFixedUpdate = false;

    #endregion


    #region Init

	/// <summary>
    /// 
    /// </summary>
    void Awake()
    {

    }


    /// <summary>
    /// 
    /// </summary>
    void Start()
    {

    }

    #endregion


    #region Update

    /// <summary>
    /// 
    /// </summary>
    void Update()
    {
        if (!useFixedUpdate)
            SharedUpdate(Time.deltaTime);
    }


    /// <summary>
    /// 
    /// </summary>
    void FixedUpdate()
    {
        if (useFixedUpdate)
            SharedUpdate(Time.fixedDeltaTime);
    }


    /// <summary>
    /// 
    /// </summary>
    /// <param name="step"></param>
    private void SharedUpdate(float step)
    {
        if (!string.IsNullOrEmpty(zAxis))
            transform.position += Input.GetAxis(zAxis) * transform.forward * step * axialSpeeds.z;

        if (!string.IsNullOrEmpty(xAxis))
            transform.position += Input.GetAxis(xAxis) * transform.right * step * axialSpeeds.x;

        if (!string.IsNullOrEmpty(yAxis))
            transform.position += Input.GetAxis(yAxis) * transform.up * step * axialSpeeds.y;
    }

    #endregion

}